<template>
  <div class="table-handler">
    <div v-if="tableType != 4" class="handler-left">
      <!-- tableType 1 任务单总览 待分派任务 -->
      <!-- tableType 2 已分派未接单 -->
      <!-- tableType 3 已分派已接单 -->
      <el-button size="small" @click="assign">新增任务单</el-button>
      <!-- <el-button size="small" @click="batchExport">批量导出</el-button> -->
    </div>
    <!-- tableType 4 不显示左侧按钮 -->
    <div v-if="tableType == 4" class="handler-left">
      &nbsp;
    </div>

    <div class="handler-right">
      <div class="hand-item" @click="refreshTable">
        <i class="el-icon-refresh"></i>
      </div>
      <div class="hand-item" @click="changeTableStyle">
        <i class="el-icon-s-operation"></i>
      </div>

      <el-popover
        v-model="showFlag"
        placement="bottom"
        width="220"
        trigger="click"
        @show="showPop"
      >
        <div>设置列字段</div>
        <div v-for="(field, index) in showList" :key="index">
          <el-checkbox @change="chooseItem" v-model="field.show">{{
            field.label
          }}</el-checkbox>
        </div>

        <div class="setting-btn">
          <div style="padding-top: 5px">
            <el-checkbox @change="chooseAll" v-model="allchoose"
              >全选</el-checkbox
            >
          </div>
          <div>
            <el-button size="small" @click="showFlag = false">取消</el-button>
            <el-button size="small" @click="confirmShow"
              >确定</el-button
            >
          </div>
        </div>
        <div slot="reference" class="hand-item">
          <i class="el-icon-sort"></i>
        </div>
      </el-popover>
    </div>
  </div>
</template>

<script>
export default {
  props: ["tableData", "columns", 'tableType'],
  methods: {
    showPop() {
      this.showList = JSON.parse(JSON.stringify(this.columns));
    },
    chooseAll(val) {
      this.showList.forEach((item) => {
        item.show = val;
      });
    },
    chooseItem() {
      let trueLength = this.showList.filter((item) => item.show).length;
      if (trueLength == this.showList.length) {
        this.allchoose = true;
        return;
      }
      this.allchoose = false;
    },
    // 确认设置
    confirmShow() {
      this.showFlag = false;
      this.$emit("setColumns", this.showList);
    },
    // 批量导出
    batchExport() {
      console.log("批量导出");
    },
    // 分派
    assign() {
        this.$emit('addMission')
    },
    // 修改表格风格
    changeTableStyle() {
      this.$emit('changeTableStyle')
    },
    // 刷新表格
    refreshTable() {
      console.log("表格刷新");
    },
  },
  data() {
    return {
      allchoose: false,
      showList: [],
      showFlag: false,
    };
  },
};
</script>

<style lang='scss' scoped>
.table-handler {
  display: flex;
  height: 50px;
  align-items: center;
  justify-content: space-between;
  .handler-left {
    display: flex;
    margin-top: 4px;
  }
  .handler-right {
    margin-top: 4px;
    display: flex;
  }
  .hand-item {
    margin-left: 5px;
    border-radius: 3px;
    cursor: pointer;
    width: 31px;
    font-size: 18px;
    line-height: 30px;
    text-align: center;
    height: 30px;
    background-color: #f2f2f2;
    &:hover {
      background-color: #333333;
      color: #ffe127;
    }
  }
  .btn {
    width: 60px;
    border-radius: 3px;
  }
}
.setting-btn {
  margin-top: 10px;
  height: 40px;
  padding-top: 10px;
  // background-color: #ccc;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  .btn {
    width: 50px;
    border-radius: 3px;
  }
}

.el-checkbox__input.is-checked + .el-checkbox__label {
  color: #1a1a1a;
}
</style>